package com.tamude.gpt.controller;

import com.tamude.gpt.service.ChatGptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import reactor.core.publisher.Flux;
import util.LoginHelper;

@Controller("/chatgpt")
public class ChatGptController {

    @Autowired
    ChatGptService service;

    @GetMapping(value = "/chat",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> chatWithGpt(@RequestParam("msg")String msg,@RequestParam("pdfUrl")String pdfUrl){
        String userId = LoginHelper.getUserId();
        return service.chatWithGpt(msg,pdfUrl,userId);
    }

}
